package cn.com.anypay.manager.common.utils;

import org.springframework.stereotype.Component;

/**
 * ID生成器工厂类
 * 统一管理各种ID生成器
 */
@Component
public class IdGeneratorFactory {

    private static final SnowflakeIdGenerator SNOWFLAKE_GENERATOR = new SnowflakeIdGenerator();

    /**
     * ID生成器类型枚举
     */
    public enum IdType {
        SNOWFLAKE,      // 雪花算法
        UUID,           // UUID
        SIMPLE_UUID,    // 简化UUID
        SHORT_UUID,     // 短UUID
        BUSINESS,       // 业务ID
        DISTRIBUTED,    // 分布式ID
        UNIFIED_CHANNEL_CONFIG  // 统一渠道配置ID
    }

    /**
     * 根据类型生成ID
     * @param type ID类型
     * @return ID字符串
     */
    public static String generateId(IdType type) {
        return switch (type) {
            case SNOWFLAKE -> SNOWFLAKE_GENERATOR.nextIdStr();
            case UUID -> UuidGenerator.generateUuid();
            case SIMPLE_UUID -> UuidGenerator.generateSimpleUuid();
            case SHORT_UUID -> UuidGenerator.generateShortUuid();
            case BUSINESS -> BusinessIdGenerator.generateCustomId("BIZ", true, 6);
            case DISTRIBUTED -> DistributedIdGenerator.generateIdStr();
            case UNIFIED_CHANNEL_CONFIG -> BusinessIdGenerator.generateUnifiedChannelConfigId();
        };
    }

    /**
     * 生成雪花算法ID
     */
    public static long generateSnowflakeId() {
        return SNOWFLAKE_GENERATOR.nextId();
    }

    /**
     * 生成订单号
     */
    public static String generateOrderId() {
        return BusinessIdGenerator.generateOrderId();
    }

    /**
     * 生成支付单号
     */
    public static String generatePaymentId() {
        return BusinessIdGenerator.generatePaymentId();
    }

    /**
     * 生成商户号
     */
    public static String generateMerchantId() {
        return BusinessIdGenerator.generateMerchantId();
    }

    /**
     * 生成用户ID
     */
    public static String generateUserId() {
        return BusinessIdGenerator.generateUserId();
    }

    /**
     * 生成统一渠道配置ID
     */
    public static String generateUnifiedChannelConfigId() {
        return BusinessIdGenerator.generateUnifiedChannelConfigId();
    }
}